package com.imut.hcdp.controller;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.imut.hcdp.domain.Consumer;
import com.imut.hcdp.domain.OrderParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.imut.hcdp.common.Rst;
import com.imut.hcdp.domain.HcdpOrder;
import com.imut.hcdp.service.IHcdpOrderService;


@RestController
@RequestMapping("/system/order")
public class HcdpOrderController
{
    @Autowired
    private IHcdpOrderService hcdpOrderService;


    /**
     * 我的订单
     * @param hcdpOrder
     * @param request
     * @return
     */
    @GetMapping("/list")
    public Rst list(HcdpOrder hcdpOrder, HttpServletRequest request)
    {

        List<HcdpOrder> list = hcdpOrderService.selectHcdpOrderList(hcdpOrder);
        return Rst.success(list);
    }


    @GetMapping(value = "/{id}")
    public Rst getInfo(@PathVariable("id") Long id)
    {
        return Rst.success(hcdpOrderService.selectHcdpOrderById(id));
    }


    /**
     * 火车票下单
     * @param orderParam
     * @return
     */
    @PostMapping
    public Rst add(@RequestBody OrderParam orderParam)
    {
        return Rst.success("出票成功！",hcdpOrderService.order(orderParam,"add"));
    }


    /**
     * 未支付取消订单
     * @param orderId
     * @return
     */
    @GetMapping("/cancelOrder")
    public Rst cancelOrder(Long orderId)
    {
        return Rst.success(hcdpOrderService.cancelOrder(orderId));
    }

    /**
     * 改签
     * 规则：只能改签当天始发且同行程的车票。每人一天只能改签一次，
     * @return
     */
    @PostMapping("/changeVisa")
    public Rst changeVisa(@RequestBody OrderParam orderParam){
        return hcdpOrderService.changeVisa(orderParam);
    }


    /**
     * 退款
     * @return
     */
    @GetMapping("/refund")
    public Rst refund(Long orderId){
        return Rst.success(hcdpOrderService.refund(orderId));
    }



	@DeleteMapping("/{id}")
    public Rst remove(@PathVariable Long id)
    {
        return Rst.success(hcdpOrderService.deleteHcdpOrderById(id));
    }
}
